package socket3;

import java.io.*;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Clent {
    private Socket socket;
    public Clent(){
        try {
            System.out.println("客户端正在启动");
            socket = new Socket("127.0.0.1",8088);
            System.out.println("已经与服务器建立连接");
            start();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void start(){
        try {
            OutputStream os = socket.getOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(os, StandardCharsets.UTF_8);
            BufferedWriter bw = new BufferedWriter(osw);
            PrintWriter pw = new PrintWriter(bw, true);
            Scanner can = new Scanner(System.in);
            while (true){
                System.out.println("请输入");
                String a = can.nextLine();
            if ("exit".equalsIgnoreCase(a)) {
                break;
            }
                pw.println(a);
        }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        new Clent();
    }
}
